package top.psjj.news.service.impl;

import top.psjj.news.dao.NewsDao;
import top.psjj.news.dao.TypeDao;
import top.psjj.news.po.TNews;
import top.psjj.news.po.TType;
import top.psjj.news.service.NewsService;

import java.util.List;

/**
 * @Auther:小陈的Java
 */
public class NewsServiceImpl implements NewsService {
    private NewsDao newsDao = new NewsDao();
    private TypeDao typeDao = new TypeDao();
    @Override
    public void add(TNews news) throws Exception {
        newsDao.add(news);
    }

    @Override
    public List<TNews> list(String sql) throws Exception {
        List<TNews> list = newsDao.queryAll(sql);
        for(TNews news : list){
            int typeId = news.getTypeId();
            TType type = typeDao.queryTypeById(typeId);
            news.settType(type);
        }
        return list;
    }

    @Override
    public void del(int id) throws Exception {
        newsDao.del(id);
    }

    @Override
    public TNews queryTNewsById(int id) throws Exception {
        return newsDao.queryTNewsById(id);
    }

    @Override
    public void modify(TNews tNews) throws Exception {
        newsDao.update(tNews);
    }

    @Override
    public List<TNews> getImgList() throws Exception {
        return newsDao.getImgList();
    }

    @Override
    public TNews getHeader() throws Exception {
        return newsDao.getHeader();
    }

    @Override
    public List<TNews> getUpdateNews() throws Exception {
        return newsDao.getUpdateNews();
    }

    @Override
    public List<TNews> getHotNews() throws Exception {
        return newsDao.getHotNews();
    }

    @Override
    public TNews queryById(int id) throws Exception {
        return newsDao.queryNewsById(id);
    }

}
